package com.letv.android.client.fragment;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.BatteryManager;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnTouchListener;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RelativeLayout;
import android.widget.SeekBar;
import android.widget.SeekBar.OnSeekBarChangeListener;
import android.widget.TextView;
import com.ledim.app.LeDimApplication;
import com.ledim.bean.LedimEpisodeBean;
import com.ledim.datastatistics.LeDimAnalysisUtils;
import com.ledim.utils.ConstantUtil;
import com.ledim.utils.LogUtil;
import com.ledim.utils.ToastUtil;
import com.letv.android.client.LetvSDK;
import com.letv.android.client.album.controller.AlbumLoadController;
import com.letv.android.client.album.controller.VolumnChangeStyle;
import com.letv.android.client.constant.LetvSDKConstant;
import com.letv.android.client.controller.AlbumGestureObservable;
import com.letv.android.client.controller.ScreenObservable;
import com.letv.android.client.episode.PlayAlbumController;
import com.letv.android.client.utils.LetvBlockLogic.OnBlockCallBack;
import com.letv.android.client.view.LetvSeekBar;
import com.letv.android.client.view.PlayLoadLayout;
import com.letv.android.client.view.ScrollTextView;
import com.letv.android.client.view.WatchingFocusRelativeLayout;
import com.letv.android.client.webview.LetvWebViewActivity;
import com.letv.android.young.client.R;
import com.letv.business.flow.album.AlbumPlayFlow;
import com.letv.business.flow.album.AlbumPlayFlowObservable;
import com.letv.business.flow.album.AlbumPlayFlowObservable.InitDownloadBtnNotify;
import com.letv.business.flow.album.PlayObservable;
import com.letv.business.flow.album.PlayObservable.BatteryStatusNotify;
import com.letv.business.flow.album.model.AlbumStreamSupporter;
import com.letv.core.api.LetvRequest;
import com.letv.core.api.MediaAssetApi;
import com.letv.core.bean.AlbumNew;
import com.letv.core.bean.DataHull;
import com.letv.core.bean.IVideo;
import com.letv.core.bean.RealPlayUrlInfoBean;
import com.letv.core.bean.TimestampBean;
import com.letv.core.bean.VideoFileBean;
import com.letv.core.bean.VideoPlayerBean;
import com.letv.core.config.LetvConfig;
import com.letv.core.constant.LetvConstant;
import com.letv.core.constant.LetvConstant.DialogMsgConstantId;
import com.letv.core.constant.NetworkConstant;
import com.letv.core.constant.PlayConstant;
import com.letv.core.db.PreferencesManager;
import com.letv.core.download.image.ImageDownloader;
import com.letv.core.network.volley.VolleyRequest;
import com.letv.core.network.volley.VolleyResponse;
import com.letv.core.network.volley.toolbox.SimpleResponse;
import com.letv.core.network.volley.toolbox.VolleyNoCache;
import com.letv.core.parser.RealPlayUrlInfoParser;
import com.letv.core.parser.VideoPlayerParser;
import com.letv.core.utils.LetvSDKUtils;
import com.letv.core.utils.LetvTools;
import com.letv.core.utils.LetvUtils;
import com.letv.core.utils.LogInfo;
import com.letv.core.utils.NetworkUtils;
import com.letv.core.utils.PlayUtils;
import com.letv.core.utils.PlayUtils.PLAY_LEVEL;
import com.letv.core.utils.StatisticsUtils;
import com.letv.core.utils.StringUtils;
import com.letv.core.utils.TipUtils;
import com.letv.core.utils.UIsUtils;
import com.letv.datastatistics.DataStatistics;
import com.letv.datastatistics.util.PageIdConstant;
import com.letv.pp.func.CdeHelper;
import com.letv.tracker2.agnes.VideoPlay;
import com.letv.tracker2.enums.PlayStart;
import java.io.File;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Observable;

//import com.letv.download.manager.DownloadManager;

//import com.letv.android.client.controller.ScreenProjectionController.OnPushToTvResponseCallback;

//import com.letv.android.client.service.FloatingWindowPlayerService;

/**
 * 点播全屏播放控制器fragment
 *
 * @author zhuqiao
 */
public class AlbumFullControllerFragment extends AlbumBaseControllerFragment
        implements OnBlockCallBack {

    /**
     * 1080or4K 推广链接地址
     */
    private String mUriLinkString1080 =
            "http://m.shop.letv.com/?cps_id=le_app_apprx_other_appbfycjds_brand_h_qr0610";
    private String mUriLinkString4K =
            "http://m.shop.letv.com/?cps_id=le_app_apprx_other_appbfy1080p_brand_h_msqgcjds0701";
    private String mUriLinkStringOther =
            "http://m.shop.letv.com/?cps_id=le_app_apprx_other_appbfycjds_brand_h_qr06101";

    public static boolean mIsFromGlsb = false; // 切换码流标记
    public static boolean mIsUserClick = false; // 是否是用户点击

    private ImageView mBack;

    private TextView mStreamSelectBox; // 清晰度选择框

    private TextView mScreenProjectionButton; // 投屏按钮
    private TextView mPushToSuperTV; // 投屏-推送到乐视电视
    private TextView mCacheToSuperTV; // 投屏-缓存到乐视电视
    private TextView mDlna; // 投屏-DLNA

    private TextView mWindowModeButton; // 小窗按钮
    private TextView mCacheButton; // 缓存按钮
    private TextView mFromMButton; // 来源乐视按钮
    private TextView mEpisodeButton; // 选集按钮
    private SeekBar mVolumeBar; // 音量调节栏

    private View mScreenProjectionLayout; // 投屏布局
    private View mStreamSelectLayout; // 清晰度选择布局
    private View mVolumeLayout; // 音量布局

    private TextView mBlockComplainTextView; // 卡顿投诉视图

    private RadioButton mLowButton; // 极速按钮
    private RadioButton mStandardButton; // 标清按钮
    private RadioButton mHighButton; // 高清按钮
    private RadioButton mSuperHighButton; // 超清按钮
    private RadioButton m4KButton; // 4K按钮
    private RadioButton m1080PButton; // 1080P按钮
    @SuppressWarnings("unused")
    private RadioButton mDecodingSwitchButton; // 解码切换（软解-硬解）按钮

    private ImageView mNetImageView;// 网络imageview
    private ImageView mBatteryImageView;// 电量imageview
    private TextView mTimeTextView;// 时间textview
    private ImageView mSwitchImageView;

    private View mTopRadioGroup;// 顶部按钮group
    private View mTopFrame;
    private View mBottomFrame;// 底部栏

    private String mNoNetworkTip; // 无网提示语

    /**
     * 全屏清晰度切换 推广按钮
     **/
    private View mTvSpreadView;
    /**
     * 1080、4k示意图imageview
     **/
    private ImageView mStreamLogoImageView;
    /**
     * 1080、4k说明TextView
     **/
    private TextView mStreamIntroTextView;
    /**
     * 1080、4k了解更多view
     **/
    private View mStreamSpreadMoreView;

    /**
     * 顶部右侧view
     **/
    private View mTopRightView;

    /**
     * 看点layout
     **/
    private WatchingFocusRelativeLayout mWatchingFocusLayout;

    /**
     * 音量seekbar是否被触摸
     **/
    private boolean mIsVolumeSeekBarTouch;

    /**
     * 声音布局是否重新设置过位置
     **/
    private boolean mHasSoundLayoutPlaced;

    public static boolean mIsFirstInitLayout = true;

    /**
     * 下载只显示一次提示的标记
     */
    private boolean mIsShowToast = true;

    // Dlna投屏控制器
    // private DlnaController mDlnaController;

    private int mColorGrey;
    private int mColorWhite;
    private int mColorSelect;
    private int mBgDisable;

    private String downloadUrl;

    private RelativeLayout.LayoutParams mSelectStreamParams;
    private RelativeLayout.LayoutParams mScreenParams;

    private FrameLayout mLastAndNextView;
    private TextView mLast;
    private TextView mNext;

    private boolean mIsHideLayout = true;

    private ArrayList<LedimEpisodeBean> mData = new ArrayList<LedimEpisodeBean>();

    /**
     * 全半屏切换
     */
    private OnClickListener mSwitchClick = new OnClickListener() {

        @Override
        public void onClick(View v) {
            mActivity.getController().half();
        }
    };

    public AlbumFullControllerFragment(Context context, View view) {
        super(context, view);
        initView();
    }

    public void setLaunchMode(int launchMode) {
        mLaunchMode = launchMode;
    }

    public void setIs4d(boolean is4d) {
        mIs4d = is4d;
    }

    @Override
    protected void initView() {
        mIsHalf = false;

        mColorGrey = mActivity.getResources().getColor(R.color.letv_color_ffa1a1a1);
        mColorWhite = mActivity.getResources().getColor(R.color.letv_color_ffffff);
        mColorSelect = mActivity.getResources().getColor(R.color.yellow_text_color);
        mBgDisable = R.drawable.letv_play_album_full_btn;

        /**
         * 初始化顺序：从上到下再从左到右
         */
        // 视频标题
        mTitleTextView = (ScrollTextView) mContentView.findViewById(R.id.full_controller_title);
        // 小窗按钮
        mWindowModeButton = (TextView) mContentView.findViewById(R.id.full_controller_pip);

        /**
         * 投屏相关视图
         */
        mScreenProjectionButton = (TextView) mContentView.findViewById(R.id.full_controller_push);
        mScreenProjectionLayout = mContentView.findViewById(R.id.full_controller_push_layout);
        mPushToSuperTV =
                (TextView) mScreenProjectionLayout.findViewById(R.id.full_content_supertv_push);
        mCacheToSuperTV =
                (TextView) mScreenProjectionLayout.findViewById(R.id.full_content_supertv_download);
        mDlna = (TextView) mScreenProjectionLayout.findViewById(R.id.dlna);

        //来源乐视按钮
        mFromMButton = (TextView) mContentView.findViewById(R.id.tv_from_m);
        // 缓存按钮
        mCacheButton = (TextView) mContentView.findViewById(R.id.full_controller_download);
        // 选集按钮
        mEpisodeButton = (TextView) mContentView.findViewById(R.id.full_controller_select_episode);
        // 横竖屏锁定按钮
        mScreenOrientationLock = (ImageView) mContentView.findViewById(R.id.full_controller_lock);
        // 播放-暂停按钮
        mPlayImageView = (ImageView) mContentView.findViewById(R.id.full_controller_play);
        // 进度条
        mSeekBar = (LetvSeekBar) mContentView.findViewById(R.id.full_controller_seekbar);
        // 音量按钮
        mVolumeImageView = (ImageView) mContentView.findViewById(R.id.full_controller_sound);
        // 音量布局
        mVolumeLayout = mContentView.findViewById(R.id.full_controller_sound_frame);
        // 音量调节控件
        mVolumeBar = (SeekBar) mContentView.findViewById(R.id.full_controller_sound_seekbar);
        // 清晰度选择按钮
        mStreamSelectBox = (TextView) mContentView.findViewById(R.id.full_controller_hd);
        // 清晰度选择布局
        mStreamSelectLayout = mContentView.findViewById(R.id.full_controller_select_stream_frame);
        /**
         * 清晰度单选框
         */
        mLowButton = (RadioButton) mContentView.findViewById(R.id.full_low_text);
        mStandardButton = (RadioButton) mContentView.findViewById(R.id.full_standard_text);
        mHighButton = (RadioButton) mContentView.findViewById(R.id.full_high_text);
        mSuperHighButton = (RadioButton) mContentView.findViewById(R.id.full_super_high_text);
        m4KButton = (RadioButton) mContentView.findViewById(R.id.full_1080_text);
        m1080PButton = (RadioButton) mContentView.findViewById(R.id.full_4K_text);
        mStreamSpreadMoreView = mContentView.findViewById(R.id.tv_spread_click);
        mStreamIntroTextView =
                (TextView) mContentView.findViewById(R.id.full_controller_stream_introduce);
        mStreamLogoImageView =
                (ImageView) mContentView.findViewById(R.id.full_controller_stream_logo);

        // 全屏半屏切换按钮
        mSwitchImageView = (ImageView) mContentView.findViewById(R.id.full_controller_half);

        //        mTitleDot = mContentView.findViewById(R.id.full_controller_skip_begin);
        //        mTrailerDot = mContentView.findViewById(R.id.full_controller_skip_end);

        mNetImageView = (ImageView) mContentView.findViewById(R.id.full_net);
        mBatteryImageView = (ImageView) mContentView.findViewById(R.id.full_battery);
        mTimeTextView = (TextView) mContentView.findViewById(R.id.full_time);

        mStreamSelectLayout.measure(0, 0);
        mVolumeLayout.measure(0, 0);
        mDecodingSwitchButton = (RadioButton) mContentView.findViewById(R.id.changeStreamDecoder);
        mBlockComplainTextView = (TextView) mContentView.findViewById(R.id.buffer);
        mTvSpreadView = mContentView.findViewById(R.id.full_controller_tv_spread);

        mInterceptClickView =
                mContentView.findViewById(R.id.player_full_controller_intercept_click_view);

        mTopRadioGroup = mContentView.findViewById(R.id.full_controller_top_rb);
        mBottomFrame = mContentView.findViewById(R.id.full_controller_bottom_frame);
        mTopFrame = mContentView.findViewById(R.id.full_controller_top_frame);
        mTopRightView = mContentView.findViewById(R.id.full_controller_top_right_frame);

        mWatchingFocusLayout =
                (WatchingFocusRelativeLayout) mContentView.findViewById(R.id.layout_watchFocus);

        //上一集下一集控制
        mLastAndNextView =
                (FrameLayout) mContentView.findViewById(R.id.full_controller_last_and_next_view);
        mLast = (TextView) mContentView.findViewById(R.id.full_controller_last);
        mNext = (TextView) mContentView.findViewById(R.id.full_controller_next);

        mStreamSelectBox.setVisibility(View.GONE);

        mDlna.setVisibility(View.GONE);
        // 小米不显示小窗
        if (LetvUtils.getBrandName().toLowerCase().contains("xiaomi")) {
            mWindowModeButton.setVisibility(View.GONE);
        }

        super.initView();

        initClick();
        initSoundSeekBarListener();
        initUriLink();
        initFullState();
        onTimeChange();
        onNetChange();

        //网络连接失败，请检查您的网络
        mNoNetworkTip = TipUtils.getTipMessage(mActivity, "100008", R.string.load_data_no_net);
        String[] streamNames = PlayUtils.getStreamLevelName(mActivity);
        mLowButton.setText(streamNames[0]);
        mStandardButton.setText(streamNames[1]);
        mHighButton.setText(streamNames[2]);
        mSuperHighButton.setText(streamNames[3]);

    }

    // 加载时不显示播放暂停按钮
    public void showLoad(boolean show) {
        if (show) {
            mPlayImageView.setVisibility(View.GONE);
        } else {
            if (mIsHideLayout) {
                mPlayImageView.setVisibility(View.VISIBLE);
            }
        }
    }

    //亮度提示框
    public void showBrightness() {
        mIsHideLayout = false;
        mPlayImageView.setVisibility(View.GONE);
    }

    //进度提示框
    public void showSeekProgress() {
        mIsHideLayout = false;
        mPlayImageView.setVisibility(View.GONE);
    }

    //声音提示框
    public void showVolume() {
        mIsHideLayout = false;
        mPlayImageView.setVisibility(View.GONE);
    }

    //隐藏提示框
    public void hideLayout() {
        mIsHideLayout = true;
    }

    public void setEpisode(ArrayList<LedimEpisodeBean> data) {
        mData = data;
        AlbumPlayFlow flow = mActivity.getFlow();
        if (flow != null && flow.getPlayRecord() != null &&
                flow.getPlayRecord().getChannelId() == ConstantUtil.ChannelType.tv ||
                flow.getPlayRecord().getChannelId() == ConstantUtil.ChannelType.cartoon) {
            if (mData.size() > 0) {
                mLastAndNextView.setVisibility(View.VISIBLE);
            }
            for (int i = 0; i < mData.size(); i++) {
                if (mData.get(i).id == flow.getVid() && i == 0) {
                    mLast.setVisibility(View.GONE);
                    break;
                } else {
                    mLast.setVisibility(View.VISIBLE);
                }
                if (mData.get(i).id == flow.getVid() && i == mData.size() - 1) {
                    mNext.setVisibility(View.GONE);
                    break;
                } else {
                    mNext.setVisibility(View.VISIBLE);
                }
            }

        } else {
            mLastAndNextView.setVisibility(View.GONE);
        }

    }

    private void initClick() {
        // 投屏功能3个按钮的点击响应
        mPushToSuperTV.setOnClickListener(this);
        mCacheToSuperTV.setOnClickListener(this);
        mDlna.setOnClickListener(this);

        //屏蔽半屏全屏切换按钮
        mSwitchImageView.setOnClickListener(mSwitchClick);
        mScreenProjectionButton.setOnClickListener(this);
        mStreamSelectBox.setOnClickListener(this);
        mVolumeImageView.setOnClickListener(this);
        mLowButton.setOnClickListener(this);
        mStandardButton.setOnClickListener(this);
        mHighButton.setOnClickListener(this);
        mSuperHighButton.setOnClickListener(this);
        m4KButton.setOnClickListener(this);
        m1080PButton.setOnClickListener(this);
        mStreamSpreadMoreView.setOnClickListener(this);
        mWindowModeButton.setOnClickListener(this);
        mEpisodeButton.setOnClickListener(this);
        mBlockComplainTextView.setOnClickListener(this);
        // 初始化click状态和TabsFragment中底部downloadBtn click事件保持一致
        mCacheButton.setOnClickListener(this);
        mFromMButton.setOnClickListener(this);

        mBack = (ImageView) mActivity.findViewById(R.id.full_controller_back);
        mTvSpreadView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                // 屏蔽底下点击事件
            }
        });

        mLast.setOnClickListener(this);
        mNext.setOnClickListener(this);
        mBack.setOnClickListener(this);
    }

    /**
     * 初始化音量seerkbar滑动事件
     */
    private void initSoundSeekBarListener() {
        mVolumeBar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                delayHide();
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                removeHideHandler();
            }

            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                removeHideHandler();
                int max = seekBar.getMax();
                int volumeMax = mActivity.getGestureController()
                                         .setSoundVolume(progress, mIsVolumeSeekBarTouch);
                // zhuqiao dlna
                // if (playAlbumController.dlna.isDlnaState) {
                // playAlbumController.dlna.isTouchForVolume = true;
                // int volume = (int) ((float) progress / playAlbumController.getMaxSoundVolume() * 100);
                // playAlbumController.dlna.volume = String.valueOf(volume);
                // }
                changeSoundState(progress, max);
                if (max != volumeMax) {
                    if (progress <= max) {
                        seekBar.setMax(volumeMax);
                    } else {
                        seekBar.setProgress(max);
                    }

                }
            }
        });
        mVolumeBar.setOnLongClickListener(null);
        mVolumeBar.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                if (event.getAction() == MotionEvent.ACTION_MOVE) {
                    mIsVolumeSeekBarTouch = true;
                } else if (event.getAction() == MotionEvent.ACTION_UP) {
                    mIsVolumeSeekBarTouch = false;
                    mActivity.getGestureController().setVolumeLayoutVisibility(false);
                    delayHide();

                    // zhuqiao dlna
                    // if (playAlbumController.dlna.isDlnaState && !TextUtils.isEmpty(playAlbumController.dlna.volume))
                    // {
                    // Bundle bundle = new Bundle();
                    // bundle.putString("volume", playAlbumController.dlna.volume);
                    // playAlbumController.dlna.sendControlAction("set_volume", bundle);
                    // }
                }
                return false;
            }
        });
    }

    @Override
    protected void onSeekBarTouchListener(android.view.MotionEvent event) {
        super.onSeekBarTouchListener(event);
        if (event.getAction() == MotionEvent.ACTION_UP) {
            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c67", "1001", 4, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
        } else if (event.getAction() == MotionEvent.ACTION_DOWN) {
            hidePop(-1);
        }
    }

    @Override
    protected void onSeekProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
        if (fromUser) {
            mWatchingFocusLayout.onProgressChanged(seekBar, progress, fromUser);
        }
    }

    /**
     * 初始化uri链接地址
     */
    private void initUriLink() {
        String urlLink1080 = TipUtils.getTipMessage(mActivity, DialogMsgConstantId.CONSTANT_100022);
        if (TextUtils.isEmpty(urlLink1080)) {
            m1080PButton.setVisibility(View.GONE);
        } else {
            m1080PButton.setVisibility(View.VISIBLE);
            mUriLinkString1080 = urlLink1080;
        }

        String uriLink4k = TipUtils.getTipMessage(mActivity, DialogMsgConstantId.CONSTANT_100023);
        if (TextUtils.isEmpty(uriLink4k)) {
            m4KButton.setVisibility(View.GONE);
        } else {
            m4KButton.setVisibility(View.VISIBLE);
            mUriLinkString4K = uriLink4k;
        }
    }

    public void initFullState() {
        //        if (mSwitchImageView == null) {
        //            return;
        //        }

        LogInfo.log("zhuqiao", "is 4d video:" + mIs4d);
        if (mLaunchMode == PlayConstant.LAUNCH_MODE_VIDEO || mIs4d ||
                mLaunchMode == PlayConstant.LAUNCH_MODE_URI) {
            mScreenOrientationLock.setVisibility(View.GONE);
            //            mSwitchImageView.setVisibility(View.GONE);
        }

        if (mIs4d || mLaunchMode == PlayConstant.LAUNCH_MODE_URI) {
            mStreamSelectBox.setVisibility(View.GONE);
            mScreenProjectionButton.setVisibility(View.GONE);
            mCacheButton.setVisibility(View.GONE);
            mEpisodeButton.setVisibility(View.GONE);
        }
    }

    /**
     * 初始化高清标清选项功能
     */
    private void initStream() {
        if (mActivity.getFlow() == null) {
            return;
        }
        mStreamSelectBox.setVisibility(View.VISIBLE);
        AlbumPlayFlow flow = mActivity.getFlow();

        //        flow.setCurrenStreamFromFullController();

        int playLevel = flow.getPlayLevel();

        boolean isLocalFile = flow.isDownloadFile();
        int downloadStreamLevel = flow.getDownloadStreamLevel();

        String[] streamLevels = PlayUtils.getStreamLevelName(mActivity);
        String superHdName = streamLevels[3];
        String hdName = streamLevels[2];
        String standardName = streamLevels[1];
        String lowName = streamLevels[0];

        if (isLocalFile) {
            String downloadStreamName = hdName;
            // 1 高清，2 标清，0 流畅
            if (downloadStreamLevel == 1) {
                downloadStreamName = superHdName;
            } else if (downloadStreamLevel == 0) {
                downloadStreamName = standardName;
            }
            mStreamSelectBox.setText(downloadStreamName);
        } else {
            mStreamSelectBox.setText(PlayUtils.getPlayLevelZh(superHdName, hdName, standardName, lowName, playLevel));
        }

        int streamCount = flow.getStreamSupporter().getStreamCount(flow.getLevelList());
        if (streamCount >= 1 && !flow.isDolby()) {
            mStreamSelectBox.setEnabled(true);
            recoverFullPlayControllerHd();

            if (flow.isDownloadFile()) {
                initStreamWhenIsLocal();
            } else {
                initStreamWhenOnline();
            }
        }

        if (flow.getLaunchMode() == PlayConstant.PLAY_DEFAULT) {
            mStreamSelectBox.setVisibility(View.GONE);
        }

        if (mIsFirstInitLayout) {
            mIsFirstInitLayout = false;
        }

        setStreamButtonEnableByLevel(playLevel);

        if (flow.isDownloadFile()) {
            setStreamButtonSelectColor(flow.getSelectStream());
        } else {
            setStreamButtonSelectColor(playLevel);
        }
    }

    /**
     * 恢复点击4K、1080P之前的状态
     */
    private void recoverFullPlayControllerHd() {
        if (mActivity.getFlow() == null) {
            return;
        }
        AlbumPlayFlow flow = mActivity.getFlow();
        AlbumStreamSupporter supporter = flow.getStreamSupporter();

        if (flow.isDownloadFile()) {
            return;
        }

        if (supporter.hasSuperHd) {
            mSuperHighButton.setTextColor(mColorWhite);
            mSuperHighButton.setEnabled(true);
        } else {
            mSuperHighButton.setTextColor(mColorGrey);
            mSuperHighButton.setEnabled(false);
        }

        if (supporter.hasHd) {
            mHighButton.setTextColor(mColorWhite);
            mHighButton.setEnabled(true);
        } else {
            mHighButton.setTextColor(mColorGrey);
            mHighButton.setEnabled(false);
        }

        if (supporter.hasStandard) {
            mStandardButton.setTextColor(mColorWhite);
            mStandardButton.setEnabled(true);
        } else {
            mStandardButton.setTextColor(mColorGrey);
            mStandardButton.setEnabled(false);
        }

        if (supporter.hasLow) {
            mLowButton.setTextColor(mColorWhite);
            mLowButton.setEnabled(true);
        } else {
            mLowButton.setTextColor(mColorGrey);
            mLowButton.setEnabled(false);
        }

        if (mTvSpreadView.getVisibility() != View.VISIBLE) {
            switch (flow.getPlayLevel()) {
                case PLAY_LEVEL.LOW:
                    mLowButton.setChecked(true);
                    break;
                case PLAY_LEVEL.HIGH:
                    mHighButton.setChecked(true);
                    break;
                case PLAY_LEVEL.STANDARD:
                    mStandardButton.setChecked(true);
                    break;
                case PLAY_LEVEL.SUPERHIGH:
                    mSuperHighButton.setChecked(true);
                    break;
            }
        }
    }

    /**
     * 本地视频初始化码流信息
     */
    private void initStreamWhenIsLocal() {
        if (mActivity.getFlow() == null) {
            return;
        }
        AlbumPlayFlow flow = mActivity.getFlow();

        switch (flow.getDownloadStreamLevel()) {
            case 1:// 高清
                mHighButton.setEnabled(false);
                mHighButton.setVisibility(View.GONE);
                mStandardButton.setEnabled(false);
                mStandardButton.setVisibility(View.GONE);
                mLowButton.setEnabled(false);
                mLowButton.setVisibility(View.GONE);

                mSuperHighButton.setVisibility(View.VISIBLE);
                mSuperHighButton.setEnabled(true);
                mSuperHighButton.setSelected(true);
                // mSuperHighBtn.setOnClickListener(play_super_high_listener);
                flow.setSelectStream(4);
                break;
            case 0:// 流畅
                mHighButton.setVisibility(View.GONE);
                mSuperHighButton.setVisibility(View.GONE);
                mLowButton.setVisibility(View.GONE);

                mStandardButton.setVisibility(View.VISIBLE);
                mStandardButton.setEnabled(true);
                // mStandardBtn.setOnClickListener(play_low_listener);
                mStandardButton.setSelected(true);
                flow.setSelectStream(2);
                break;
            case 2: // 标清
                mLowButton.setVisibility(View.GONE);
                mSuperHighButton.setVisibility(View.GONE);
                mStandardButton.setVisibility(View.GONE);

                mHighButton.setVisibility(View.VISIBLE);
                mHighButton.setEnabled(true);
                mHighButton.setSelected(true);
                // mHighBtn.setOnClickListener(play_high_listener);
                flow.setSelectStream(3);
                break;
            default:
                break;
        }
    }

    /**
     * 在线视频初始化码流信息
     */
    private void initStreamWhenOnline() {
        if (mActivity.getFlow() == null) {
            return;
        }
        AlbumPlayFlow flow = mActivity.getFlow();

        if (flow.getPlayRecord() != null) {
            if (flow.getPlayRecord().getChannelId() == ConstantUtil.ChannelType.tv ||
                    flow.getPlayRecord().getChannelId() == ConstantUtil.ChannelType.cartoon) {

                if (mData.size() > 0) {
                    mLastAndNextView.setVisibility(View.VISIBLE);
                }
                for (int i = 0; i < mData.size(); i++) {
                    if (mData.get(i).id == flow.getVid() && i == 0) {
                        mLast.setVisibility(View.GONE);
                        break;
                    } else {
                        mLast.setVisibility(View.VISIBLE);
                    }
                    if (mData.get(i).id == flow.getVid() && i == mData.size() - 1) {
                        mNext.setVisibility(View.GONE);
                        break;
                    } else {
                        mNext.setVisibility(View.VISIBLE);
                    }
                }

            } else {
                mLastAndNextView.setVisibility(View.GONE);
            }
        }

        AlbumStreamSupporter supporter = flow.getStreamSupporter();

        if (!supporter.hasSuperHd) {
            mSuperHighButton.setEnabled(false);
            mSuperHighButton.setTextColor(mActivity.getResources()
                                                   .getColor(R.color.letv_color_ff969696));
            mSuperHighButton.setVisibility(View.GONE);
        } else {
            mSuperHighButton.setVisibility(View.VISIBLE);
            mSuperHighButton.setEnabled(true);
            // mSuperHighBtn.setOnClickListener(play_super_high_listener);
        }

        if (!supporter.hasHd) {
            mHighButton.setEnabled(false);
            mHighButton.setVisibility(View.GONE);
        } else {
            mHighButton.setVisibility(View.VISIBLE);
            mHighButton.setEnabled(true);
            // mHighBtn.setOnClickListener(play_high_listener);
        }

        if (!supporter.hasStandard) {
            mStandardButton.setEnabled(false);
            mStandardButton.setVisibility(View.GONE);
        } else {
            mStandardButton.setVisibility(View.VISIBLE);
            mStandardButton.setEnabled(true);
            // mStandardBtn.setOnClickListener(play_standard_listener);
        }

        if (!supporter.hasLow) {
            mLowButton.setEnabled(false);
            mLowButton.setTextColor(mActivity.getResources().getColor(R.color.letv_color_ff969696));
            mLowButton.setVisibility(View.GONE);
        } else {
            mLowButton.setVisibility(View.VISIBLE);
            mLowButton.setEnabled(true);
            // mLowBtn.setOnClickListener(play_low_listener);
        }
    }

    /**
     * 设置选择码流按钮是否可点击
     *
     * @param level
     */
    private void setStreamButtonEnableByLevel(int level) {
        switch (level) {
            case PLAY_LEVEL.LOW:
                mLowButton.setClickable(false);
                mStandardButton.setClickable(true);
                mHighButton.setClickable(true);
                mSuperHighButton.setClickable(true);
                break;
            case PLAY_LEVEL.STANDARD:
                mLowButton.setClickable(true);
                mStandardButton.setClickable(false);
                mHighButton.setClickable(true);
                mSuperHighButton.setClickable(true);
                break;
            case PLAY_LEVEL.HIGH:
                mLowButton.setClickable(true);
                mStandardButton.setClickable(true);
                mHighButton.setClickable(false);
                mSuperHighButton.setClickable(true);
                break;
            case PLAY_LEVEL.SUPERHIGH:
                mLowButton.setClickable(true);
                mStandardButton.setClickable(true);
                mHighButton.setClickable(true);
                mSuperHighButton.setClickable(false);
                break;
            default:
                break;
        }
    }

    /**
     * 设置选择码流按钮选中状态
     *
     * @param selectedStream
     */
    private void setStreamButtonSelectColor(int selectedStream) {
        LogInfo.log("zhuqiao", "selectedStream:" + selectedStream);

        mLowButton.setTextColor(mColorWhite);
        mStandardButton.setTextColor(mColorWhite);
        mHighButton.setTextColor(mColorWhite);
        mSuperHighButton.setTextColor(mColorWhite);

        String[] streamLevels = PlayUtils.getStreamLevelName(mActivity);

        // 1极速 ，2 流畅， 3 标清， 4高清
        if (selectedStream == PLAY_LEVEL.LOW) {
            mLowButton.setTextColor(mColorSelect);
            mStreamSelectBox.setText(streamLevels[0]);
        } else if (selectedStream == PLAY_LEVEL.STANDARD) {
            mStandardButton.setTextColor(mColorSelect);
            mStreamSelectBox.setText(streamLevels[1]);
        } else if (selectedStream == PLAY_LEVEL.HIGH) {
            mHighButton.setTextColor(mColorSelect);
            mStreamSelectBox.setText(streamLevels[2]);
        } else if (selectedStream == PLAY_LEVEL.SUPERHIGH) {
            mSuperHighButton.setTextColor(mColorSelect);
            mStreamSelectBox.setText(streamLevels[3]);
        }

        m4KButton.setTextColor(mColorGrey);
        m1080PButton.setTextColor(mColorGrey);
    }

    /**
     * 判断选集类型
     */
    public void checkVideoType() {
        if (mActivity.getPlayAlbumController() == null) {
            return;
        }

        boolean isVideoNormal = mActivity.getPlayAlbumController().isVideoNormal();
        int isShowMode = mActivity.getPlayAlbumController().isShowMode;
        LogInfo.log("zhuqiao",
                "checkVideoType：isVideoNormal:" + isVideoNormal + ",isShowMode: " + isShowMode);
        if (isVideoNormal) {
            switch (isShowMode) {
                case 0:
                    mEpisodeButton.setText(R.string.episode);
                    break;
                case 1:
                    mEpisodeButton.setText(R.string.periods);
                    break;
                case 2:
                    mEpisodeButton.setText(R.string.list);
                    break;
                case 3:
                    mEpisodeButton.setText(R.string.related);
                    break;
            }
        } else {
            if (mActivity.getPlayAlbumController().isPlayFromAlbumFlag()) {
                mEpisodeButton.setText(R.string.related);
            } else {
                mEpisodeButton.setText(R.string.list);
            }
        }
    }

    /**
     * 所有按钮点击事件的唯一入口
     */
    @Override
    public void onClick(View v) {
        super.onClick(v);
        int id = v.getId();
        if (id == R.id.full_controller_back) {
            clickBack();
        } else {
            if (mActivity.getFlow() == null) {
                return;
            }
            AlbumPlayFlow flow = mActivity.getFlow();
            AlbumStreamSupporter supporter = flow.getStreamSupporter();

            if (id == R.id.full_controller_pip) {
                playInWindowMode();
            } else if (id == R.id.full_controller_push) {
                clickScreenProjection();
            } else if (id == R.id.full_controller_hd) {
                mTopFrame.setVisibility(View.GONE);
                mBottomFrame.setVisibility(View.GONE);
                if (mLastAndNextView.getVisibility() == View.VISIBLE) {
                    mLastAndNextView.setVisibility(View.INVISIBLE);
                }
                LogInfo.log("sguotao", "click the hd!");
                clickSelectDH();
            } else if (id == R.id.full_controller_sound) {
                LogInfo.log("sguotao", "click the sound!");
                clickSoundImage();
            } else if (id == R.id.full_low_text) {
                clickStreamBtn(PLAY_LEVEL.LOW, supporter.hasLow,
                        flow.getPlayLevel() != PLAY_LEVEL.LOW, mLowButton.getText().toString());
            } else if (id == R.id.full_standard_text) {
                clickStreamBtn(PLAY_LEVEL.STANDARD, supporter.hasStandard,
                        flow.getPlayLevel() != PLAY_LEVEL.STANDARD, mStandardButton.getText()
                                                                                   .toString());
            } else if (id == R.id.full_high_text) {
                clickStreamBtn(PLAY_LEVEL.HIGH, supporter.hasHd,
                        flow.getPlayLevel() != PLAY_LEVEL.HIGH, mHighButton.getText().toString());
            } else if (id == R.id.full_super_high_text) {
                clickStreamBtn(PLAY_LEVEL.SUPERHIGH, supporter.hasSuperHd,
                        flow.getPlayLevel() != PLAY_LEVEL.SUPERHIGH, mSuperHighButton.getText()
                                                                                     .toString());
            } else if (id == R.id.full_1080_text) {
                click1080();
            } else if (id == R.id.full_4K_text) {
                click4k();
            } else if (id == R.id.tv_spread_click) {
                clickLeanMore();
            } else if (id == R.id.full_content_supertv_push) {
                // 投屏-推送到超级电视
                LogInfo.LogStatistics("点播--投屏-推送超级电视");
                StatisticsUtils.staticticsInfoPost(mActivity, "0", "c654", "1010", 1, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
            } else if (id == R.id.full_content_supertv_download) {
            } else if (id == R.id.dlna) {
                clickBack();
            } else if (id == R.id.full_controller_select_episode) {
                // 选集
                clickfromEpisode();
                //            setVisibilityForEpisode(true);
                //            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c65", "0002", 6, null, PageIdConstant.fullPlayPage,
                //                null, null, null, null, null);
            } else if (id == R.id.buffer) {
                // 卡顿投诉
                clickBlockComplain();
            } else if (id == R.id.full_controller_download) {
                // 缓存下载
                clickCacheBtn();
            } else if (id == R.id.tv_from_m) {
                //来源m站
                clickFromBtn();
            } else if (id == R.id.full_controller_half) {
                mActivity.getController().half();
            } else if (id == R.id.full_controller_last) {
                mActivity.playerLast(); //播放上一集

                delayHide();
            } else if (id == R.id.full_controller_next) {
                mActivity.finishPlayer(); //播放下一集
                delayHide();
            }
        }

    }



    /**
     * 点击选集 打开乐视app下载的h5界面
     * 利用sp存储相关设置，如果liteApp已经下载，未安装，则直接进入安装界面；若未下载，则直接进入h5界面。
     * by pangzhen
     */
    private void clickfromEpisode() {
        if (PreferencesManager.getInstance().getLiteDownloadCompleted()) {
            String mLiteAppName = PreferencesManager.getInstance().getLiteDownLoadName();
            String mLiteAppPath = PreferencesManager.getInstance().getLiteDownLoadPath();
            LogInfo.log("pangzhen", "安装包 ：" + mLiteAppPath + "/" + mLiteAppName);
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            String type = "application/vnd.android.package-archive";
            File file = new File(mLiteAppPath + "/" + mLiteAppName);
            intent.setDataAndType(Uri.fromFile(file), type);
            mActivity.startActivity(intent);
        } else {
            LetvWebViewActivity.launch(mActivity, LetvConstant.APP_DOWNLOAD_URL, mActivity.getResources()
                                                                                          .getString(R.string.moreaboutusactivity_webtitle));
        }

        //选集的数据统计
        DataStatistics.getInstance()
                      .sendFromActionInfo(mActivity, null, null, null, "c65", "6", "集数", "32", LetvUtils
                              .getClientVersionName(mActivity));
    }

    private void clickCacheBtn() {
        //因版权原因，暂不提供缓存
        String permissionDeclineStr =
                LetvTools.getTextFromServer(mActivity, "100016", mActivity.getString(R.string.half_bottom_download_unable));
        //网络不给力，请检查网络设置
        String netErrStr =
                LetvTools.getTextFromServer(mActivity, "500003", mActivity.getString(R.string.load_data_no_net_playerlibs));
        if (!NetworkUtils.isNetworkAvailable(mActivity)) {
            ToastUtil.toast(netErrStr);
            return;
        }

        PlayAlbumController playAlbumController = mActivity.getPlayAlbumController();
        if (!isCanSingleVideoDownload() && !isCanNormalVideoDownload()) {
            ToastUtil.toast(permissionDeclineStr);
        }

        AlbumPlayFlow flow = mActivity.getFlow();
        VideoFileBean videoFileBean = flow.getmVideoFile();
        if (null != videoFileBean) {
            requestDownlaodUrl(videoFileBean.getMmsid(), flow.getVid());
        }

        // 5.7需求
        if (playAlbumController.getVideoBean() != null) {
            LogInfo.LogStatistics("缓存");
            StatisticsUtils.staticticsInfoPost(playAlbumController.getActivity(), "0", "h22", "0006", 2, null, PageIdConstant.halpPlayPage,
                    playAlbumController.getVideoBean().getCid() + "",
                    playAlbumController.getVideoBean().getPid() + "",
                    playAlbumController.vid + "", null, null);
        }

    }

    /**
     * 其中利用sp存储相关设置，如果liteApp已经下载，未安装，则直接进入安装界面；若未下载，则直接进入h5界面。
     */
    private void clickFromBtn() {
        if (PreferencesManager.getInstance().getLiteDownloadCompleted()) {
            String mLiteAppName = PreferencesManager.getInstance().getLiteDownLoadName();
            String mLiteAppPath = PreferencesManager.getInstance().getLiteDownLoadPath();
            LogInfo.log("pangzhen", "安装包 ：" + mLiteAppPath + "/" + mLiteAppName);
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_VIEW);
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            String type = "application/vnd.android.package-archive";
            File file = new File(mLiteAppPath + "/" + mLiteAppName);
            intent.setDataAndType(Uri.fromFile(file), type);
            mActivity.startActivity(intent);
        } else {
            LetvWebViewActivity.launch(mActivity, LetvConstant.APP_DOWNLOAD_URL, mActivity.getResources()
                                                                                          .getString(R.string.moreaboutusactivity_webtitle));

            LogInfo.LogStatistics("来源:乐视");
        }
        DataStatistics.getInstance()
                      .sendFromActionInfo(mActivity, null, null, null, "c65", "3", "letv", "32", LetvUtils
                              .getClientVersionName(mActivity));
    }

    private boolean isCanSingleVideoDownload() {
        boolean res = true;
        PlayAlbumController playAlbumController = mActivity.getPlayAlbumController();
        if (playAlbumController != null) {
            if (playAlbumController.isVideoNormal()) {
                res = false;
            } else if (!playAlbumController.isVideoNormal() &&
                    playAlbumController.getVideoBean() != null &&
                    !playAlbumController.getVideoBean().canDownload()) {
                res = false;
            }
        }

        LogInfo.log("hong", "isCanSingleVideoDownload res : " + res + " mIsVideoNormal : " +
                playAlbumController.isVideoNormal());
        return res;
    }

    private boolean isCanNormalVideoDownload() {
        boolean res = true;
        PlayAlbumController playAlbumController = mActivity.getPlayAlbumController();
        if (playAlbumController != null) {
            // 非单视频半屏页只判断专辑是否可下载，不需要判断视频是否可下载
            if (!playAlbumController.isVideoNormal()) {
                res = false;
            } else if (playAlbumController.isVideoNormal() &&
                    playAlbumController.getAlbum() != null &&
                    !playAlbumController.getAlbum().canDownload()) {
                res = false;
            }
        }
        return res;
    }

    @Override
    public void initProcess(int max, int progress, int buffer) {
        super.initProcess(max, progress, buffer);
        initStream();
        drawWatchFocus();
    }

    private void drawWatchFocus() {
        // 根据看点列表绘制看点信息，延迟2s画看点，否则布局可能还没初始化完成，所获取的尺寸可能有误
        mHandler.postDelayed(new Runnable() {

            @Override
            public void run() {
                if (mActivity.getFlow() != null && mActivity.getFlow().getPlayingVideo() != null) {
                    mWatchingFocusLayout.drawWatchingFocus(mSeekBar, mContentView, mActivity.getFlow()
                                                                                            .getPlayingVideo()
                                                                                            .getWatchingFocusList(), mPlayImageView, mContentView
                            .findViewById(R.id.full_controller_bottom_right_frame));
                }
            }
        }, 2000);
    }

    @Override
    public void hideAllControllerLayout() {
    }

    @Override
    public void updateSkipState(long beginTime, long endTime) {
        if (mSoundW == -1) {
            mSoundW = UIsUtils.measure(mVolumeImageView)[0];
        }
        if (mHdW == -1) {
            mHdW = UIsUtils.measure(mStreamSelectBox)[0];
        }
        super.updateSkipState(beginTime, endTime);
    }

    private void occurBlockPostBtn() {
        if (mBlockComplainTextView.getVisibility() == View.GONE) {
            setBlockBtnVisibile(true);
            LogInfo.log("zhuqiao", "---topright occurBlockPostBtn");
            removeHideHandler();
            delayHide();
        }
    }

    @Override
    public void setBlockBtnVisibile(boolean show) {
        mBlockComplainTextView.setVisibility(show ? View.VISIBLE : View.GONE);
        if (show) {
            LogInfo.log("zhuqiao", "卡顿曝光");
            StatisticsUtils.staticticsInfoPost(mActivity, "19", "c65", null, 2, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
        }
    }

    /**
     * 播放-暂停按钮的处理
     */
    @Override
    protected void clickPauseOrPlay() {
        super.clickPauseOrPlay();
        // zhuqiao dlna
        delayHide();
        if (mIsPlaying) {
            mIsUserClick = true;
            mActivity.getController().pause(true);
            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c67", "1000", 2, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
        } else {
            // zhuqiao dlna
            mActivity.getController().start();
            setControllerVisibility(View.VISIBLE, true, Style.FULL);
            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c67", "1004", 1, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
        }
    }

    public void onVolumeChange(int max, int progress, VolumnChangeStyle style, boolean show) {
        if (progress > max) {
            return;
        }

        mVolumeLayout.setVisibility(View.INVISIBLE);

        mVolumeBar.setMax(max);
        if (style == VolumnChangeStyle.NONE) {
            mVolumeBar.setProgress(progress);
        } else {
            int temp = mVolumeBar.getProgress();
            if (style == VolumnChangeStyle.UP) {
                if (temp == progress) {
                    progress += 1;
                } else if (temp > progress) {
                    progress = temp + 1;
                }
            } else {
                if (temp == progress) {
                    progress -= 1;
                } else if (temp < progress) {
                    progress = temp + 1;
                }
            }
            mVolumeBar.setProgress(progress);
        }

        changeSoundState(progress, max);

        delayHide();
    }

    @Override
    public void update(Observable observable, Object data) {
        super.update(observable, data);

        if (data instanceof String) {
            String notify = (String) data;
            if (TextUtils.equals(ScreenObservable.ON_CONFIG_CHANGE, notify)) {
                // 横竖屏切换
                if (!UIsUtils.isLandscape(mActivity)) {
                    setVisibilityForEpisode(false);
                } else {
                    if (AlbumLoadController.sShouldPush) {
                        //                        processScreenProjection(mActivity, ScreenProjectionController.SCR_PROJ_TYPE_PUSH,
                        //                            mActivity.getLoadListener());
                    }
                    AlbumLoadController.sShouldPush = false;
                    showTopDownLoadButtonStatus();
                    updateWindowPlayStatus();
                }
            } else if (TextUtils.equals(AlbumGestureObservable.ON_CLICK, notify)) {
                // 单击
                if (!checkIsPauseAdShowWhenClick()) {
                    if (UIsUtils.isLandscape(mActivity)) {
                        if (isVisible()) {
                            setVisibilityForEpisode(false);
                        }
                        setControllerVisibility(isVisible() ? View.GONE : View.VISIBLE, true);
                    }
                }
            } else if (TextUtils.equals(AlbumGestureObservable.ON_GESTURE_CHANGE, notify)) {
                hidePop(-1);
            } else if (TextUtils.equals(AlbumPlayFlowObservable.ON_STREAM_INIT, notify)) {
                initStream();
            } else if (TextUtils.equals(PlayObservable.ON_TIME_CHANGE, notify)) {
                // 时间变化
                onTimeChange();
            } else if (TextUtils.equals(PlayObservable.ON_NET_CHANGE, notify)) {
                // 网络变化
                onNetChange();
            } else if (TextUtils.equals(AlbumPlayFlowObservable.ON_START_FETCHING, notify)) {
                setVisibilityForEpisode(false);
                AlbumPlayFlow flow = mActivity.getFlow();
                if (flow.isDownloadFile()) {
                    setStreamButtonSelectColor(flow.getSelectStream());
                } else {
                    setStreamButtonSelectColor(flow.getPlayLevel());
                }
                mWatchingFocusLayout.clearFocus();
            } else if (TextUtils.equals(AlbumPlayFlowObservable.ON_REQUEST_VIDEO_INFO_SUCCESS, notify)) {
                updateWindowPlayStatus();
            } else if (TextUtils.equals(AlbumGestureObservable.DOUBLE_CLICK, notify)) {
                if (UIsUtils.isLandscape(mActivity)) {
                    clickPauseOrPlay();
                }
            }

        } else if (data instanceof BatteryStatusNotify) {
            // 电量变化
            BatteryStatusNotify notify = (BatteryStatusNotify) data;
            onBatteryChange(notify.batteryStatus, notify.batterycurPower);
        } else if (data instanceof InitDownloadBtnNotify) {
            InitDownloadBtnNotify notify = (InitDownloadBtnNotify) data;
            showTopDownLoadButtonStatus();
            initDownload(notify.albumNew);
        } else if (data instanceof AlbumGestureObservable.VolumeChangeNotify) {
            AlbumGestureObservable.VolumeChangeNotify notify =
                    (AlbumGestureObservable.VolumeChangeNotify) data;
            onVolumeChange(notify.max, notify.progress, notify.style, notify.showSeekbar);
        }
    }

    public void updateWindowPlayStatus() {
        boolean enabled = isAllowWindowPlay();

        setWindowClickable(enabled);
    }

    private boolean isAllowWindowPlay() {
        return !isTopicAlbumVideo() && !isVipTryAndSee() && !mIs4d;
    }

    /**
     * 是否是专题视频
     */
    private boolean isTopicAlbumVideo() {
        boolean result = false;
        if (mLaunchMode == PlayConstant.LAUNCH_MODE_TOPIC_VIDEO ||
                mLaunchMode == PlayConstant.LAUNCH_MODE_TOPIC_ALBUM) {
            result = true;
        }
        return result;
    }

    /**
     * 当前播放的视频是否是6分钟会员试看视频
     */
    private boolean isVipTryAndSee() {
        boolean result = false;
        if ((mActivity.getVipTrailListener() != null &&
                mActivity.getVipTrailListener().isVipVideo())) {
            result = true;
        }
        return result;
    }

    /**
     * 时间变化
     */
    private void onTimeChange() {
        Calendar mCalendar = Calendar.getInstance();
        mCalendar.setTimeInMillis(System.currentTimeMillis());
        int hour = mCalendar.get(Calendar.HOUR_OF_DAY);
        int minite = mCalendar.get(Calendar.MINUTE);
        mTimeTextView.setText(StringUtils.getStringTwo(String.valueOf(hour)) + ":" +
                StringUtils.getStringTwo(String.valueOf(minite)));
    }

    /**
     * 网络变化
     */
    private void onNetChange() {
        switch (NetworkUtils.getNetworkType(mActivity)) {
            case NetworkConstant.NETWORK_TYPE_NO_NET:
                mNetImageView.setImageResource(R.drawable.letv_net_no);
                break;
            case NetworkConstant.NETWORK_TYPE_WIFI:
                setEnable(true);
                mNetImageView.setImageResource(R.drawable.letv_net_wifi);
                break;
            case NetworkConstant.NETWORK_TYPE_2G:
                mNetImageView.setImageResource(R.drawable.letv_net_2g);
                break;
            case NetworkConstant.NETWORK_TYPE_3G:
                mNetImageView.setImageResource(R.drawable.letv_net_3g);
                break;
        }
    }

    /**
     * 电量变化
     *
     * @param curStatus
     * @param curPower
     */
    private void onBatteryChange(int curStatus, int curPower) {
        boolean isCharging = false;
        switch (curStatus) {
            case BatteryManager.BATTERY_STATUS_CHARGING:// 充电状态
                isCharging = true;
                break;
            case BatteryManager.BATTERY_STATUS_DISCHARGING:// 放电状态
                break;
            case BatteryManager.BATTERY_STATUS_NOT_CHARGING:// 未充电
                break;
            case BatteryManager.BATTERY_STATUS_FULL:// 充满电
                break;
            case BatteryManager.BATTERY_STATUS_UNKNOWN:// 未知状态
                break;
            default:
                break;
        }
        if (isCharging) {
            mBatteryImageView.setImageResource(R.drawable.letv_battery_charge);
        } else {
            if (curPower >= 80) {
                mBatteryImageView.setImageResource(R.drawable.letv_battery5);
            } else if (curPower >= 60) {
                mBatteryImageView.setImageResource(R.drawable.letv_battery4);
            } else if (curPower >= 40) {
                mBatteryImageView.setImageResource(R.drawable.letv_battery3);
            } else if (curPower >= 20) {
                mBatteryImageView.setImageResource(R.drawable.letv_battery2);
            } else if (curPower >= 0) {
                mBatteryImageView.setImageResource(R.drawable.letv_battery1);
            }
        }
    }

    /**
     * 点击投屏
     */
    private void clickScreenProjection() {
        delayHide();

        if (!NetworkUtils.isNetworkAvailable(mActivity)) {
            ToastUtil.toast(mNoNetworkTip);
            return;
        }

        hidePop(1);

        if (mScreenProjectionLayout.getVisibility() == View.VISIBLE) {
            mScreenProjectionLayout.setVisibility(View.GONE);
            setButtonSelect(mScreenProjectionButton, false);
            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c650", "1009", 2, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
        } else {
            mScreenProjectionLayout.setVisibility(View.VISIBLE);
            setButtonSelect(mScreenProjectionButton, true);
            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c650", "1009", 1, null, PageIdConstant.fullPlayPage, null, null, null, null, null);

            if (mScreenParams != null) {
                return;
            }

            int[] location = new int[2];
            mScreenProjectionButton.getLocationOnScreen(location);
            mScreenParams = (RelativeLayout.LayoutParams) mScreenProjectionLayout.getLayoutParams();
            mScreenParams.leftMargin = location[0] - UIsUtils.dipToPx(mActivity, 30);
            mScreenParams.topMargin = location[1] + mScreenProjectionButton.getMeasuredHeight() +
                    UIsUtils.dipToPx(mActivity, 5);
            mScreenProjectionLayout.setLayoutParams(mScreenParams);
            mScreenProjectionLayout.requestLayout();
        }
    }

    /**
     * 首次使用投屏(推送到超级电视或者缓存到超级电视)功能的处理
     *
     * @param context
     * @param type
     *         SCR_PROJ_TYPE.PUSH-推送到超级电视 SCR_PROJ_TYPE.CACHE-缓存到超级电视
     */
    private boolean processFirstUse(final Context context, final int type) {
        //        final SharedPreferences sp = context.getSharedPreferences("gesture", Context.MODE_PRIVATE);
        //        String key = (type == ScreenProjectionController.SCR_PROJ_TYPE_PUSH ? "isFirstPush" : "isFirstDownload");
        //        boolean isFirst = sp.getBoolean(key, true);
        //        if (isFirst) {
        // 首次使用投屏功能，弹出说明对话框
        //            int textId = (type == ScreenProjectionController.SCR_PROJ_TYPE_PUSH ? R.string.double_finger_up
        //                : R.string.double_finger_down);
        //            int imageId = (type == ScreenProjectionController.SCR_PROJ_TYPE_PUSH ? R.drawable.double_finger_up
        //                : R.drawable.double_finger_down);
        //            DlnaFirstPushDialog dlg = new DlnaFirstPushDialog(context, R.style.first_push_style, textId, imageId);
        //            dlg.setOnDismissListener(new OnDismissListener() {
        //                @Override
        //                public void onDismiss(DialogInterface dialog) {
        //                    if (mIsLocked) {
        //                        if (mActivity.getController() != null) {
        //                            mActivity.getController().setLock(false);
        //                        }
        //                        mIsLocked = false;
        //                    }
        //                    setPreferenceValue(context, type, false);
        // mProjectionController = new ScreenProjectionController(mActivity, mFlow, mDialogCallBack);

        //                    mActivity.getScreenProjectionController().performScreenProject(type);
        //                }
        //            });
        //            dlg.show();
        //            if (!mIsLocked) {
        //                if (mActivity.getController() != null) {
        //                    mActivity.getController().setLock(true);
        //                }
        //                mIsLocked = true;
        //            }
        //        }
        //
        //        return isFirst;
        return false;
    }

    /**
     * 投屏处理
     *
     * @param context
     * @param type    ScreenProjectionController.SCR_PROJ_TYPE_PUSH: 推送到超级电视
     *                ScreenProjectionController.SCR_PROJ_TYPE_CACHE: 缓存到超级电视
     *                ScreenProjectionController.SCR_PROJ_TYPE_DLNA
     */
    //    public void processScreenProjection(final Context context, final int type, OnPushToTvResponseCallback callback) {
    //        hidePop(-1);
    //        if (isVisible()) {
    //            setVisibility(View.GONE);
    //        }
    //
    //        createScreenProjectionController(callback);
    //        boolean processed = processFirstUse(context, type);
    //        if (!processed) {
    //            mActivity.getScreenProjectionController().performScreenProject(type);
    //        }
    //    }

    /**
     * 创建投屏控制器
     */
    //    private void createScreenProjectionController(OnPushToTvResponseCallback callback) {
    //        if (null == mActivity.getScreenProjectionController()) {
    //            // 创建投屏控制器
    //            ScreenProjectionController controller = new ScreenProjectionController(mActivity);
    //            mActivity.setScreenProjectionController(controller);
    //        }
    //        mActivity.getScreenProjectionController().setOnPushToTvResponseCallback(callback);
    //    }

    /**
     * 设置按钮状态
     */
    private void showTopDownLoadButtonStatus() {
        boolean enabled = false;
        if (NetworkUtils.isNetworkAvailable(mActivity) && mActivity.getFlow() != null) {
            enabled = true;
            if (mActivity.getFlow().getPlayingVideo() == null) {
                mCacheButton.setTextColor(mColorGrey);
                enabled = false;
            } else if (!mActivity.getFlow().getPlayingVideo().canDownload() &&
                    mActivity.getPlayAlbumController() != null) {
                enabled = false;
            }

            if (isNotDownload()) {
                enabled = false;
            }
        }

        setButtonEnable(mCacheButton, enabled);
    }

    private void setButtonEnable(TextView textView, boolean enable) {
        if (enable) {
            setButtonSelect(textView, false);
        } else {
            textView.setBackgroundResource(mBgDisable);
            textView.setTextColor(mColorGrey);
        }
    }

    private void setButtonSelect(TextView textView, boolean select) {
        if (select) {
            textView.setBackgroundResource(R.drawable.letv_play_album_full_btn_select);
            textView.setTextColor(mActivity.getResources().getColor(R.color.yellow_text_color));
        } else {
            textView.setTextAppearance(mActivity, R.style.play_controller_btn_text);
            textView.setBackgroundResource(R.drawable.letv_btn_play_live_full_func_bg_selector);
        }
    }

    private void setWindowClickable(boolean enable) {
        if (enable) {
            setButtonSelect(mWindowModeButton, false);
            mWindowModeButton.setClickable(true);
        } else {
            mWindowModeButton.setTextColor(mColorGrey);
            mWindowModeButton.setBackgroundResource(mBgDisable);
        }
    }

    private void initDownload(final AlbumNew album) {
        mIsShowToast = true;
        final AlbumPlayFlow flow = mActivity.getFlow();
        final PlayAlbumController albumController = mActivity.getPlayAlbumController();
        if (flow == null || albumController == null) {
            return;
        }

        if (flow.getLaunchMode() == PlayConstant.PLAY_VIDEO) {
            // 单视频
            mCacheButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    hidePop(-1);
                    LogInfo.log("sguotao", "点击单视频缓存");
                    if (isNotDownload()) {
                        //版权方面受限，暂不提供缓存。
                        ToastUtil.toast(TipUtils.getTipMessage(mActivity, DialogMsgConstantId.CONSTANT_100016, R.string.download_copy_right));
                    } else if (!NetworkUtils.isNetworkAvailable(mActivity)) {
                        //网络不给力，请检查网络设置
                        ToastUtil.toast(TipUtils.getTipMessage(mActivity, "100008", R.string.load_data_no_net_playerlibs));
                    } else {
                        LogInfo.log("sguotao", "OnClick--单视频缓存");
                        //                        DownloadManager.addDownload(mActivity, album, flow.getPlayingVideo(), flow.isDolby(),
                        //                            mIsShowToast, true, flow.getPlayLevel(), true, null, albumController.isVideoNormal());
                        //                        StatisticsUtils.staticticsInfoPost(mActivity, "0", "c65", "0006", 5, null,
                        //                            PageIdConstant.fullPlayPage, null, null, null, null, null);
                    }
                }
            });
        } else if (album != null && album.canDownload()) {
            mCacheButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    LogInfo.log("sguotao", "点击专辑视频缓存");
                    hidePop(-1);
                    if (isNotDownload()) {
                        //版权方面受限，暂不提供缓存
                        ToastUtil.toast(TipUtils.getTipMessage(mActivity, DialogMsgConstantId.CONSTANT_100016, R.string.download_copy_right));
                    } else if (!albumController.isVideoNormal()) {
                        if (!NetworkUtils.isNetworkAvailable(mActivity)) {
                            //网络不给力，请检查网络设置
                            ToastUtil.toast(TipUtils.getTipMessage(mActivity, "100008", R.string.load_data_no_net_playerlibs));
                        } else {
                            //                            DownloadManager.addDownload(mActivity, album, flow.getPlayingVideo(), flow.isDolby(),
                            //                                mIsShowToast, true, flow.getPlayLevel(), true, false);
                        }
                    } else if (!NetworkUtils.isNetworkAvailable(mActivity)) {
                        //网络不给力，请检查网络设置
                        ToastUtil.toast(TipUtils.getTipMessage(mActivity, "100008", R.string.load_data_no_net_playerlibs));
                    } else {
                        /*
                         * 呼出专辑下载侧边栏
                         * param1: 是否显示剧集项
                         * param2： 是否从下载入口呼出
                         */
                        //                        setVisibilityForEpisode(true, true);

                        //                        String ddUrl = flow.getAlbumUrl().ddUrl;
                        //                        parserDDUrl2Realurl(ddUrl);

                        AlbumPlayFlow flow = mActivity.getFlow();
                        VideoFileBean videoFileBean = flow.getmVideoFile();
                        if (null != videoFileBean) {
                            requestDownlaodUrl(videoFileBean.getMmsid(), flow.getVid());
                        }

                    }
                    StatisticsUtils.staticticsInfoPost(mActivity, "0", "c65", "0006", 5, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
                }
            });
        } else {
            mCacheButton.setOnClickListener(new OnClickListener() {

                @Override
                public void onClick(View v) {
                    LogInfo.log("sguotao", "不能缓存");
                    ToastUtil.toast(TipUtils.getTipMessage(mActivity, DialogMsgConstantId.CONSTANT_100016, R.string.download_copy_right));
                }
            });
        }
    }

    /**
     * 解析DDurl
     *
     * @param ddUrl
     */
    private void parserDDUrl2Realurl(String ddUrl) {
        new LetvRequest<RealPlayUrlInfoBean>(mActivity).setUrl(ddUrl)
                                                       .setCache(new VolleyNoCache())
                                                       .setParser(new RealPlayUrlInfoParser())
                                                       .setRequestType(VolleyRequest.RequestManner.NETWORK_ONLY)
                                                       .setMaxRetries(AlbumPlayFlow.MAX_RETRY_TIMES)
                                                       .setTag(AlbumPlayFlow.REQUEST_VIDEO_PLAY_URL)
                                                       .setCallback(new SimpleResponse<RealPlayUrlInfoBean>() {
                                                           @Override
                                                           public void onNetworkResponse(
                                                                   VolleyRequest<RealPlayUrlInfoBean> request,
                                                                   RealPlayUrlInfoBean result,
                                                                   DataHull hull,
                                                                   VolleyResponse.NetworkResponseState state) {
                                                               super.onNetworkResponse(request, result, hull, state);
                                                               if (state ==
                                                                       VolleyResponse.NetworkResponseState.SUCCESS) {
                                                                   LogInfo.log("sguotao",
                                                                           "downloadUrl---" +
                                                                                   result.getRealUrl());
                                                                   downloadUrl =
                                                                           result.getRealUrl();

                                                                   IVideo mVideo = new IVideo();
                                                                   mVideo.setmDownloadUrl(downloadUrl);
                                                                   LetvSDK.getInstance()
                                                                          .getCallBack()
                                                                          .onEvent(LetvSDKConstant.EVENT_START_DOWNLOAD, "event_start_download", mVideo);
                                                               }
                                                           }
                                                       })
                                                       .add();

    }

    private void requestDownlaodUrl(String mmsid, long mVid) {
        String tm = String.valueOf(TimestampBean.getTm().getCurServerTime());
        String key =
                TimestampBean.generateVideoFileKey(String.valueOf(mmsid), String.valueOf(tm)); //0 --> mmsid
        String url = MediaAssetApi.getInstance(LeDimApplication.getInstance())
                                  .getDownloadUrl(mActivity, mmsid, "no", tm, key, mVid); //0 --> mmsid
        //得到接口地址，再去获取视频的调度地址；调度地址成功之后，在获取真实的下载地址

        new LetvRequest<VideoPlayerBean>(mActivity).setUrl(url)
                                                   .setCache(new VolleyNoCache())
                                                   .setParser(new VideoPlayerParser())
                                                   .setTag(AlbumPlayFlow.REQUEST_VIDEO_PLAY_URL)
                                                   .setCallback(new SimpleResponse<VideoPlayerBean>() {

                                                       @Override
                                                       public void onNetworkResponse(
                                                               VolleyRequest<VideoPlayerBean> request,
                                                               VideoPlayerBean result,
                                                               DataHull hull,
                                                               VolleyResponse.NetworkResponseState state) {
                                                           if (state ==
                                                                   VolleyResponse.NetworkResponseState.SUCCESS) {
                                                               LogInfo.log("sguotao", result.getVideoFile()
                                                                                            .getMp4_350()
                                                                                            .getMainUrl());

                                                               String ddUrl = result.getVideoFile()
                                                                                    .getMp4_350()
                                                                                    .getMainUrl();

                                                               StringBuilder mDDUrl =
                                                                       new StringBuilder();
                                                               mDDUrl.append(ddUrl);
                                                               mDDUrl.append("&pcode=");
                                                               mDDUrl.append(LetvConfig.getPcode(mActivity));
                                                               mDDUrl.append("&version=");
                                                               mDDUrl.append(LetvUtils.getClientVersionName(mActivity));
                                                               mDDUrl.append("&uuid=");
                                                               mDDUrl.append(LetvUtils.getUUID(mActivity));

                                                               getDownloadUrlByCde(mDDUrl.toString());

                                                           } else {
                                                               LogInfo.log("sguotao", "get download url failed.");
                                                           }
                                                       }

                                                   })
                                                   .add();
    }

    private void getDownloadUrlByCde(String ddUrl) {
        LogInfo.log("sguotao", "防盗链:" + ddUrl);
        LetvSDKUtils.reStartCde(mActivity);
        CdeHelper cdeHelper = LetvSDKUtils.getCdeHelper(mActivity);
        if (cdeHelper != null) {
            // 加密开关开启,获取加密过后的url
            if (PreferencesManager.getInstance(mActivity).isLinkShellSwitch()) {
                String linkshellUrl = LetvSDKUtils.getCdeHelper(mActivity).getLinkshellUrl(ddUrl);
                LogInfo.log("sguotao", "linkShell:" + linkshellUrl);

                parseRealDownloadUrl(linkshellUrl);
            }
        }
    }

    private void parseRealDownloadUrl(String ddUrl) {
        new LetvRequest<RealPlayUrlInfoBean>(mActivity).setUrl(ddUrl)
                                                       .setCache(new VolleyNoCache())
                                                       .setParser(new RealPlayUrlInfoParser())
                                                       .setRequestType(VolleyRequest.RequestManner.NETWORK_ONLY)
                                                       .setMaxRetries(AlbumPlayFlow.MAX_RETRY_TIMES)
                                                       .setTag(AlbumPlayFlow.REQUEST_VIDEO_PLAY_URL)
                                                       .setCallback(new SimpleResponse<RealPlayUrlInfoBean>() {
                                                           @Override
                                                           public void onNetworkResponse(
                                                                   VolleyRequest<RealPlayUrlInfoBean> request,
                                                                   RealPlayUrlInfoBean result,
                                                                   DataHull hull,
                                                                   VolleyResponse.NetworkResponseState state) {
                                                               super.onNetworkResponse(request, result, hull, state);
                                                               if (state ==
                                                                       VolleyResponse.NetworkResponseState.SUCCESS) {
                                                                   LogInfo.log("sguotao",
                                                                           "download url:" +
                                                                                   result.getRealUrl());

                                                                   IVideo mVideo = new IVideo();
                                                                   mVideo.setmDownloadUrl(result.getRealUrl());
                                                                   LetvSDK.getInstance()
                                                                          .getCallBack()
                                                                          .onEvent(LetvSDKConstant.EVENT_START_DOWNLOAD, "event_start_download", mVideo);
                                                               }
                                                           }
                                                       })
                                                       .add();
    }

    private boolean isNotDownload() {
        boolean res = false;
        if (mActivity.getPlayAlbumController().isVideoNormal()) {
            if (mActivity.getFlow().getAlbum() != null) {
                res = !mActivity.getFlow().getAlbum().canDownload();
            }
        } else {
            res = mActivity.getFlow().getPlayingVideo() != null &&
                    !mActivity.getFlow().getPlayingVideo().canDownload();
        }
        return res;
    }

    /**
     * 点击选择清晰度
     */
    private void clickSelectDH() {
        mIsFromGlsb = false;
        delayHide();

        if (!NetworkUtils.isNetworkAvailable(mActivity)) {
            ToastUtil.toast(mNoNetworkTip);
            return;
        }

        hidePop(2);

        hideTvSpreadView();
        if (mActivity.getFlow() != null && !mActivity.getFlow().isDownloadFile()) {
            setStreamButtonSelectColor(mActivity.getFlow().getPlayLevel());
        }

        if (mStreamSelectLayout.getVisibility() == View.VISIBLE) {
            mTopFrame.setVisibility(View.VISIBLE);
            mBottomFrame.setVisibility(View.VISIBLE);
            if (mLastAndNextView.getVisibility() == View.INVISIBLE) {
                mLastAndNextView.setVisibility(View.VISIBLE);
            }
            mStreamSelectLayout.setVisibility(View.GONE);
            setButtonSelect(mStreamSelectBox, false);
        } else {
            mStreamSelectLayout.setVisibility(View.VISIBLE);
            setButtonSelect(mStreamSelectBox, true);
            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c67", "1005", 5, null, PageIdConstant.fullPlayPage, null, null, null, null, null);

            if (mSelectStreamParams != null) {
                return;
            }

            //            int[] locations = new int[2];
            //            mStreamSelectBox.getLocationOnScreen(locations);
            //            int x = locations[0];// 获取组件当前位置的横坐标
            //            int y = locations[1];// 获取组件当前位置的纵坐标
            //            mSelectStreamParams = (RelativeLayout.LayoutParams) mStreamSelectLayout.getLayoutParams();
            //            mSelectStreamParams.leftMargin = x + mStreamSelectBox.getWidth() / 2 - UIsUtils.dipToPx(mActivity, 140) / 2;
            //            mSelectStreamParams.topMargin = y - mStreamSelectLayout.getMeasuredHeight() - UIsUtils.dipToPx(mActivity, 0);//
            //
            //            mStreamSelectLayout.setLayoutParams(mSelectStreamParams);
            //            mStreamSelectLayout.requestLayout();
        }
    }

    /**
     * 声音图片点击事件
     */
    private void clickSoundImage() {
        delayHide();

        hidePop(3);

        if (mVolumeLayout.getVisibility() != View.VISIBLE) {
            mVolumeLayout.setVisibility(View.VISIBLE);
            if (!mHasSoundLayoutPlaced) {
                placeSoundLayout();
                mHasSoundLayoutPlaced = true;
            }
        } else {
            mVolumeLayout.setVisibility(View.GONE);
        }

        changeSoundState(mVolumeBar.getProgress(), mVolumeBar.getMax());
        int wz;
        if (mVolumeLayout.getVisibility() == View.VISIBLE) {
            wz = 1;
        } else {
            wz = 2;
        }
        if (mActivity.getFlow() != null && mActivity.getFlow().getPlayingVideo() != null) {
            StatisticsUtils.staticticsInfoPost(mActivity, "0", "c663", null, wz, null, PageIdConstant.fullPlayPage,
                    mActivity.getFlow().getPlayingVideo().getCid() + "",
                    mActivity.getFlow().getPlayingVideo().getPid() + "", "-", "-", "-");
        }
    }

    private void placeSoundLayout() {
        int[] size = UIsUtils.measure(mVolumeLayout);
        int[] locations = new int[2];
        mVolumeImageView.getLocationOnScreen(locations);
        int x = locations[0];// 获取组件当前位置的横坐标
        int y = locations[1];// 获取组件当前位置的纵坐标
        RelativeLayout.LayoutParams params =
                (RelativeLayout.LayoutParams) mVolumeLayout.getLayoutParams();
        params.leftMargin = x + mVolumeImageView.getMeasuredWidth() / 2 - size[0] / 2;
        params.topMargin = y - mVolumeLayout.getMeasuredHeight() - UIsUtils.dipToPx(mActivity, 5);

        mVolumeLayout.setLayoutParams(params);
        mVolumeLayout.requestLayout();
    }

    /**
     * 改变声音按钮状态
     */
    private void changeSoundState(int value, int maxValue) {
        boolean isShow = mVolumeLayout.getVisibility() == View.VISIBLE;

        if (value == maxValue) {
            mVolumeImageView.setImageResource(
                    isShow ? R.drawable.letv_sound_three_active : R.drawable.letv_sound_three);
        } else if (value > maxValue / 2) {
            mVolumeImageView.setImageResource(
                    isShow ? R.drawable.letv_sound_two_active : R.drawable.letv_sound_two);
        } else if (value > 0) {
            mVolumeImageView.setImageResource(
                    isShow ? R.drawable.letv_sound_one_active : R.drawable.letv_sound_one);
        } else {
            mVolumeImageView.setImageResource(
                    isShow ? R.drawable.letv_sound_zero_active : R.drawable.letv_sound_zero);
            // playAlbumController.isNoSound = true;
        }
    }

    /**
     * 切换码流点击事件
     *
     * @param playLevel
     * @param hasLevel
     *         是否包含当前码流
     * @param shouldChange
     *         是否应该切换
     * @param name
     *         码流名字
     */
    private void clickStreamBtn(int playLevel, boolean hasLevel, boolean shouldChange,
                                String name) {
        LogUtil.e("clickStreamBtn====");
        PlayLoadLayout.mIsShowBlock = false;
        changeStreamByUser();
        mBlockComplainTextView.setVisibility(View.GONE);
        mIsFromGlsb = true;

        if (!hasLevel) {
            return;
        }

        mTvSpreadView.setVisibility(View.INVISIBLE);
        hidePop(-1);
        m1080PButton.setSelected(false);
        m4KButton.setSelected(false);
        setButtonSelect(mStreamSelectBox, false);

        if (shouldChange && mActivity.getFlow() != null) {
            sWaitingSwitchStreamName = name;
            mActivity.getFlow().setPlayLevel(playLevel);
            PreferencesManager.getInstance(mActivity).setPlayLevel(playLevel);
            if (mActivity.getFlow().shouldDeclineStream()) {
                //                LetvSDK.getInstance().setMemoryPlayLevel(playLevel);
            }
            setStreamButtonSelectColor(playLevel);
            mActivity.getFlow().setSelectStream(playLevel);
            mActivity.getFlow().retryPlay(false, true);
            showStreamTip(sWaitingSwitchStreamName);
            if (mActivity.getHalfControllerFragment() != null) {
                mActivity.getHalfControllerFragment().showStreamTip(sWaitingSwitchStreamName);
            }
        }
        //切换码流统计 ccx
        AlbumPlayFlow flow = mActivity.getFlow();
        VideoFileBean videoFileBean = flow.getmVideoFile();
        if (null != videoFileBean) {
            VideoPlay videoPlay = flow.getCommonVideoPlay();
            videoPlay.switchBitStream(videoFileBean.streamLevelMaps.get(playLevel));
            LeDimAnalysisUtils.reportPlayEvent(videoPlay);
            VideoPlay initVideo = flow.getCommonVideoPlay();
            initVideo.setBitStream(videoFileBean.streamLevelMaps.get(playLevel));
            initVideo.midstartInit();
            LeDimAnalysisUtils.reportPlayEvent(initVideo);
            VideoPlay midStartVideo = flow.getCommonVideoPlay();
            midStartVideo.setBitStream(videoFileBean.streamLevelMaps.get(playLevel));
            midStartVideo.midPlay(mSeekBar.getProgress(), PlayStart.Manual);
            LeDimAnalysisUtils.reportPlayEvent(midStartVideo);
        }

        switch (playLevel) {
            case PLAY_LEVEL.LOW:
                // low
                StatisticsUtils.staticticsInfoPost(mActivity, "0", "c675", "2006", 6, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
                break;
            case PLAY_LEVEL.STANDARD:
                // standard
                StatisticsUtils.staticticsInfoPost(mActivity, "0", "c675", "2005", 5, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
                break;
            case PLAY_LEVEL.HIGH:
                // high
                StatisticsUtils.staticticsInfoPost(mActivity, "0", "c675", "2004", 4, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
                break;
            case PLAY_LEVEL.SUPERHIGH:
                // superhigh
                StatisticsUtils.staticticsInfoPost(mActivity, "0", "c675", "2003", 3, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
                break;
            default:
                break;
        }
    }

    /**
     * 3g下手动改变码流flag.
     */
    private void changeStreamByUser() {
        int currentState = NetworkUtils.getNetworkType(mActivity);
        if (currentState == NetworkConstant.NETWORK_TYPE_2G ||
                currentState == NetworkConstant.NETWORK_TYPE_3G) {
            //            LetvApplication.sIsChangeStream = false;
        }
    }

    /**
     * 点击4k按钮事件
     */
    private void click4k() {
        mBlockComplainTextView.setVisibility(View.GONE);
        m1080PButton.setSelected(false);
        if (!m4KButton.isSelected()) {
            mTvSpreadView.setVisibility(View.VISIBLE);
            m4KButton.setSelected(true);
            setStreamTvSpread(DialogMsgConstantId.CONSTANT_100027, R.drawable.letv_tv_spread_4k);
            mStreamIntroTextView.setText(R.string.spread_4k);
            removeHideHandler();
        } else {
            mTvSpreadView.setVisibility(View.INVISIBLE);
            m4KButton.setSelected(false);
            delayHide();
        }
        if (mActivity.getFlow() != null) {
            mActivity.getFlow().setSelectStream(R.id.full_4K_text);
        }

        // 统计
        StatisticsUtils.staticticsInfoPost(mActivity, "0", "c675", "2001", 1, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
    }

    /**
     * 点击1080按钮事件
     */
    private void click1080() {
        mBlockComplainTextView.setVisibility(View.GONE);
        m4KButton.setSelected(false);
        if (!m1080PButton.isSelected()) {
            mTvSpreadView.setVisibility(View.VISIBLE);
            mStreamLogoImageView.setImageResource(R.drawable.letv_tv_spread_1080p);
            setStreamTvSpread(DialogMsgConstantId.CONSTANT_100026, R.drawable.letv_tv_spread_1080p);
            mStreamIntroTextView.setText(R.string.spread_1080p);
            m1080PButton.setSelected(true);
            removeHideHandler();
        } else {
            mTvSpreadView.setVisibility(View.INVISIBLE);
            m1080PButton.setSelected(false);
            delayHide();
        }
        if (mActivity.getFlow() != null) {
            mActivity.getFlow().setSelectStream(R.id.full_1080_text);
        }

        // 统计
        StatisticsUtils.staticticsInfoPost(mActivity, "0", "c675", "2002", 2, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
    }

    /**
     * 设置1080、4k说明
     */
    private void setStreamTvSpread(String messageId, int imageResId) {
        String url = TipUtils.getTipMessage(mActivity, messageId);
        if (TextUtils.isEmpty(url)) {
            ImageDownloader.getInstance(mActivity).download(mStreamLogoImageView, url);
        } else {
            mStreamLogoImageView.setImageResource(imageResId);
        }
    }

    /**
     * 点击了解更多事件
     */
    private void clickLeanMore() {
        hidePop(-1);

        String uri = "";
        String fl = "";
        if (m1080PButton.isSelected()) {
            uri = mUriLinkString1080;
            fl = "c6752";
        } else if (m4KButton.isSelected()) {
            uri = mUriLinkString4K;
            fl = "c6751";
        } else {
            uri = mUriLinkStringOther;
        }

        // 统计
        StatisticsUtils.staticticsInfoPost(mActivity, "0", fl, null, 1, null, PageIdConstant.fullPlayPage, null, null, null, null, null);

        LetvWebViewActivity.launch(mActivity, uri, mActivity.getString(R.string.letv_shop));
    }

    /**
     * 点击返回
     */
    private void clickBack() {
        //        mActivity.finish();
        mActivity.getController().half();
        //        if (mActivity.getController().fullBack()) {
        //            return;
        //        }
        //
        //        mUserClickBackTime = StringUtils.timeClockString("yyyyMMdd_HH:mm:ss");
        //        mUserClickBackStartTime = System.currentTimeMillis();
        //        delayHide();
        //        mActivity.getController().half();

        // 统计
        StatisticsUtils.staticticsInfoPost(mActivity, "0", "c65", "0005", 1, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
    }

    /**
     * 卡顿投诉
     */
    private void clickBlockComplain() {
        String cdeCode = CdeHelper.getInstance().getHelpNumber("");
        String content = TipUtils.getTipMessage(mActivity, "100017", R.string.complaintSuccess);
        if (!TextUtils.isEmpty(cdeCode)) {
            int length = cdeCode.length();
            if (length > 6) {
                String newCode = cdeCode.substring(length - 6, length);
                content = "[" + newCode + "]" + content;
            } else {
                content = "[" + cdeCode + "]" + content;
            }
        }
        content = content.replace("#", "\n");
        LogInfo.log("Emerson", "content = " + content);
        ToastUtil.toast(content);

        setBlockBtnVisibile(false);
        LogInfo.log("zhuqiao", "卡顿投诉");
        StatisticsUtils.staticticsInfoPost(mActivity, "0", "c65", "0018", 2, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
    }

    /**
     * 隐藏弹窗
     *
     * @param exceptWitch
     *         除了哪个 <br>
     *         1.投屏;2.码流;3.音量
     */
    private void hidePop(int exceptWitch) {
        if (exceptWitch != 1) {
            setButtonSelect(mScreenProjectionButton, false);
            mScreenProjectionLayout.setVisibility(View.GONE);
        }
        if (exceptWitch != 2) {
            setButtonSelect(mStreamSelectBox, false);
            mTopFrame.setVisibility(View.VISIBLE);
            mBottomFrame.setVisibility(View.VISIBLE);
            if (mLastAndNextView.getVisibility() == View.INVISIBLE) {
                mLastAndNextView.setVisibility(View.VISIBLE);
            }
            mStreamSelectLayout.setVisibility(View.GONE);
        }
        if (exceptWitch != 3) {
            mVolumeLayout.setVisibility(View.GONE);
            changeSoundState(mVolumeBar.getProgress(), mVolumeBar.getMax());
        }
    }

    /**
     * 隐藏1080、4k说明view
     */
    private void hideTvSpreadView() {
        if (mTvSpreadView.getVisibility() == View.VISIBLE) {
            mTvSpreadView.setVisibility(View.INVISIBLE);
            m1080PButton.setSelected(false);
            m4KButton.setSelected(false);
        }
        recoverFullPlayControllerHd();
    }

    /**
     * 切换到窗口模式播放
     */
    private void playInWindowMode() {
        // 统计-5.7需求
        LogInfo.LogStatistics("点播--小窗--点击");
        StatisticsUtils.staticticsInfoPost(mActivity, "0", "c65", "0014", 9, null, PageIdConstant.fullPlayPage, null, null, null, null, null);

        if (!isAllowWindowPlay()) {
            ToastUtil.toast(mActivity.getString(R.string.pop_window_useless));
            return;
        }

        //        mActivity.sendBroadcast(new Intent(FloatingWindowPlayerHelper.INTENT_FLOATING_WINDOW_SHOW));
        mActivity.finish();
        //        final Bundle bundle = genWindowPlayParams();
        // 启动窗口播放器服务
        //        FloatingWindowPlayerService.start(mActivity, bundle);
    }

    //    private Bundle genWindowPlayParams() {
    //        if (mActivity.getFlow() == null) {
    //            return null;
    //        }
    //        AlbumPlayFlow flow = mActivity.getFlow();
    //
    //        Bundle bundle = new Bundle();
    //        AlbumNew album = flow.getAlbum();
    //        VideoBean vb = flow.getPlayingVideo();
    //        bundle.putBoolean("isLive", false);
    //        bundle.putString("albumtitle", album != null ? album.getNameCn() : "");
    //        bundle.putString("order", album != null ? LetvUtils.getOrder(album.getCid()) : "-1");
    //        bundle.putLong("aid", album != null ? album.getAid() : 0);
    //        if (vb != null) {
    //            bundle.putLong("vid", vb.getVid());
    //        }
    //        bundle.putBoolean("isDolby", album != null ? album.getIsDolby() : false);
    //
    //        if (flow.isDownloadFile()) {
    //            // 有下载记录时，isLocalFile才是true,扫描的视频这个值为false
    //            bundle.putInt("launch_mode", PlayConstant.PLAY_DOWNLOAD);
    //        } else if ((album != null ? album.getAid() : 0) <= 0 && flow.getLaunchMode() == PlayConstant.PLAY_ALBUM) {
    //            // 当打开的视频为专缉但专缉id为0时，改为单视频描放
    //            // 部分视频没有aid,但此时的Launch_mode为album,此时，在打开小窗时，把launch_mode改为单视频，否则小窗无法播放该视频
    //            bundle.putInt("launch_mode", PlayConstant.PLAY_VIDEO);
    //        } else {
    //            // 以原有的launchMode打开，包括专缉，视频，以及本地扫描
    //            bundle.putInt("launch_mode", flow.getLaunchMode());
    //        }
    //
    //        bundle.putSerializable("album", album);
    //        if (vb != null) {
    //            bundle.putString("mid", vb.getMid());
    //        }
    //        bundle.putBoolean("isFromLocal", flow.isLocalFile());
    //        bundle.putInt("curPage", flow.getCurrentPage());
    //        bundle.putString("url", flow.getAlbumUrl().realUrl);
    //        bundle.putLong("lastvid", flow.getLastVideoPos());
    //        if (flow.getLaunchMode() == PlayConstant.PLAY_DEFAULT) {
    //            // 本地视频
    //            bundle.putLong("seek", flow.getLocalSeek());
    //        } else {
    //            bundle.putLong("seek", flow.getPlayInfo().currTime);
    //        }
    //        LogInfo.log("wuxinrong", "seek = " + bundle.getLong("seek"));
    //        bundle.putString(LetvConstant.Intent.Bundle.PCODE, LetvConstant.Global.PCODE);
    //        bundle.putString(LetvConstant.Intent.Bundle.VERSION, LetvConstant.Global.VERSION);
    //        bundle.putString(LetvConstant.Intent.Bundle.VIDEO_FORMAT, LetvSDK.getInstance().getVideoFormat());
    //        bundle.putString(LetvConstant.Intent.Bundle.DEVICEID, LetvUtils.generate_DeviceId(mActivity));
    //        // 是否为3G免流量
    //        bundle.putBoolean("isWo3GUser", flow.isWo3GUser());
    //
    //        // 传入视频集合
    //        bundle.putSerializable("episode", mActivity.getPlayAlbumController().videos);
    //        // 传入相关数据（猜你喜欢，相关，cms）
    //        bundle.putSerializable("related", mActivity.getPlayAlbumController().relatedBeanArray);
    //        // 传入期数视频集合数据
    //        bundle.putSerializable("episodeByDate", mActivity.getPlayAlbumController().albumNewListByDatePlayerLibs);
    //
    //        // LogInfo.log("wuxinrong", "主播放器中的播放记录 = " + mActivity.getFlow().getPlayRecord().toString());
    //        bundle.putSerializable("playRecord", mActivity.getFlow().getPlayRecord());
    //        return bundle;
    //    }

    private void setVisibilityForEpisode(boolean show) {
        setVisibilityForEpisode(show, false);
    }

    private void setVisibilityForEpisode(boolean show, boolean isFromDownload) {
        //        if (mActivity.getHalfPlayVideosFragment() != null) {
        //            if (show) {
        //                Bundle bundle = new Bundle();
        //                int launchMode = mActivity.getFlow().getLaunchMode();
        //                if (launchMode == PlayConstant.PLAY_TOPIC_VIDEO || launchMode == PlayConstant.PLAY_TOPIC_ALBUM) {
        //                    if (!mActivity.getPlayAlbumController().isVideoNormal()) {
        //                        bundle.putInt(HalfPlayVideosFragment.CURRENT_SHOW_STYLE, HalfPlayVideosFragment.TOPIC_VIDEO_LIST_CONSTANT);
        //                    }
        //                }
        ////                if (isFromDownload) {
        ////                    bundle.putBoolean(HalfPlayVideosFragment.EPISODE_FULL_SCREEN_DOWNLOAD_KEY, isFromDownload);
        ////                }
        //                mActivity.getHalfPlayVideosFragment().setArguments(bundle);
        //                mActivity
        //                    .getSupportFragmentManager()
        //                    .beginTransaction()
        //                    .replace(R.id.play_album_full_episode, mActivity.getHalfPlayVideosFragment(),
        //                        HalfPlayVideosFragment.class.getSimpleName()).commitAllowingStateLoss();
        //            } else {
        //                mActivity.getSupportFragmentManager().beginTransaction().remove(mActivity.getHalfPlayVideosFragment())
        //                    .commitAllowingStateLoss();
        //            }
        //
        //            // 屏蔽手势
        //            if (mActivity.getGestureController() != null) {
        //                mActivity.getGestureController().setGestureUseful(!show);
        //            }
        //
        //            // 隐藏底部栏
        //            mBottomFrame.setVisibility(show ? View.GONE : View.VISIBLE);
        //            // 去掉顶部buttons
        //            mTopRadioGroup.setVisibility(show ? View.GONE : View.VISIBLE);
        //            // 隐藏网络等图标
        //            mTopRightView.setVisibility(show ? View.GONE : View.VISIBLE);
        //
        //            hidePop(-1);
        //
        //            // 去掉5s隐藏
        //            if (show) {
        //                mWatchingFocusLayout.clearAnimationAndHide();
        //                removeHideHandler();
        //            } else {
        //                delayHide();
        //            }
        //        }
        // else {
        //            if (mActivity.getHalfPlayVideosFragment() == null) {
        //            }
        //        }
    }

    // -------------------- 卡顿 --------------------

    @Override
    public void commonBlock() {
        LogInfo.log("Emerson", "----ssss----commonBlock");
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                //                occurBlockPostBtn();
            }
        });
    }

    @Override
    public void blockFiveSeconds() {
        LogInfo.log("Emerson", "----ssss----blockFiveSeconds");
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                //                occurBlockPostBtn();
            }
        });
    }

    @Override
    public void blockSuggest(final String msg) {
        LogInfo.log("Emerson", "----ssss----blockSuggest");
        mHandler.post(new Runnable() {

            @Override
            public void run() {
                /**
                 * 如果此次卡顿与最近一次拖动进度条的时间间隔小于4S，则认为是由于用户频繁拖动进度条引起的自然刷新，不属于卡顿，不做卡顿提示
                 */
                if (System.currentTimeMillis() - mLastProgressTime < 4 * 1000) {
                    return;
                }

                if (UIsUtils.isLandscape(mActivity)) {
                    setVisibility(View.VISIBLE);
                }
                mStreamTipTextView.setText(msg);
                mStreamTipStreamTextView.setVisibility(View.GONE);
                mStreamCancelView.setVisibility(View.VISIBLE);
                mStreamTipView.setVisibility(View.VISIBLE);
                mHandler.postDelayed(new Runnable() {

                    @Override
                    public void run() {
                        // 片头tip提示
                        mStreamTipView.setVisibility(View.GONE);
                        setVisibility(View.GONE);
                    }
                }, 5000);
            }
        });
    }

    @Override
    public void setVisibility(int visibility) {
        super.setVisibility(visibility);
        if (visibility != View.VISIBLE) {
            // 统计-音量选择框隐藏
            if (mVolumeLayout != null && mVolumeLayout.getVisibility() == View.VISIBLE) {
                if (mActivity.getFlow() != null && mActivity.getFlow().getPlayingVideo() != null) {
                    StatisticsUtils.staticticsInfoPost(mActivity, "0", "c663", null, 2, null, PageIdConstant.fullPlayPage,
                            mActivity.getFlow().getPlayingVideo().getCid() + "",
                            mActivity.getFlow().getPlayingVideo().getPid() + "", "-", "-", "-");
                }
            } else if (mScreenProjectionLayout != null &&
                    mScreenProjectionLayout.getVisibility() == View.VISIBLE) {
                // 统计-投屏选择框隐藏
                StatisticsUtils.staticticsInfoPost(mActivity, "0", "c650", "1009", 2, null, PageIdConstant.fullPlayPage, null, null, null, null, null);
            }

            mWatchingFocusLayout.clearAnimationAndHide();
            hidePop(-1);
            if (UIsUtils.isScreenOn(mActivity)) {
                mBackForeverView.setVisibility(View.GONE);
            }
        } else if (mSeekBar.getVisibility() == View.VISIBLE) {
            drawWatchFocus();
        }
    }

    public void isFull(boolean isFull) {
        if (isFull) {
            mBack.setVisibility(View.VISIBLE);
        } else {
            mBack.setVisibility(View.INVISIBLE);
        }
    }

}
